//
//  receiveNearPeople.m
//  tcpoctest
//
//  Created by gump on 5/23/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "receiveNearPeople.h"

@implementation receiveNearPeople

-(void)processreceive
{
    //返回 14char(1),14char(1),[距离米int,用户名长度char(1),用户名char(x)]*N
    switch (getNearPeopleFilterType()) {
        case NTF_ALL:
        {
            [[DataControl shareControl].nearPeopleDistanceDic removeAllObjects];
            [[DataControl shareControl].nearPeopleShowArr removeAllObjects];
            
            while (logicsb.mrestLength > 0)
            {
                int length = [logicsb ReadIntWithTT:NTT_BIG2SMALL];
                NSString *mail = [logicsb ReadUnencodeString];
                
                if (mail != nil && [mail length] > 0)
                {
                    if (![mail isEqualToString:[DataControl shareControl].personDS.uinfo.mail])
                    {
                        if ([[DataControl shareControl].nearPeopleDistanceDic objectForKey:mail] == nil)
                        {
                            [[DataControl shareControl].nearPeopleDistanceDic
                             setObject:[NSNumber numberWithInt:length ]
                             forKey:mail];
                        }
                        
                        [[DataControl shareControl].nearPeopleShowArr addObject:mail];
                    }
                }
                
            }
            
            [DataControl shareControl].nearPeopleCurShowArr = [DataControl shareControl].nearPeopleShowArr;
            [DataControl shareControl].nearPeopleCurDic = [DataControl shareControl].nearPeopleDistanceDic;
        }
            break;
        case NTF_FEMALE:
        {
            [[DataControl shareControl].nearFemaleDic removeAllObjects];
            [[DataControl shareControl].nearFemaleShowArr removeAllObjects];
            
            while (logicsb.mrestLength > 0)
            {
                int length = [logicsb ReadIntWithTT:NTT_BIG2SMALL];
                NSString *mail = [logicsb ReadUnencodeString];
                
                if (mail != nil && [mail length] > 0)
                {
                    if (![mail isEqualToString:[DataControl shareControl].personDS.uinfo.mail])
                    {
                        if ([[DataControl shareControl].nearFemaleDic objectForKey:mail] == nil)
                        {
                            [[DataControl shareControl].nearFemaleDic
                             setObject:[NSNumber numberWithInt:length ]
                             forKey:mail];
                        }
                        
                        [[DataControl shareControl].nearFemaleShowArr addObject:mail];
                    }
                }
                
            }
            
            [DataControl shareControl].nearPeopleCurShowArr = [DataControl shareControl].nearFemaleShowArr;
            [DataControl shareControl].nearPeopleCurDic = [DataControl shareControl].nearFemaleDic;
        }
            break;
        case NTF_MALE:
        {
            [[DataControl shareControl].nearMaleDic removeAllObjects];
            [[DataControl shareControl].nearMaleShowArr removeAllObjects];
            
            while (logicsb.mrestLength > 0)
            {
                int length = [logicsb ReadIntWithTT:NTT_BIG2SMALL];
                NSString *mail = [logicsb ReadUnencodeString];
                
                if (mail != nil && [mail length] > 0)
                {
                    if (![mail isEqualToString:[DataControl shareControl].personDS.uinfo.mail])
                    {
                        
                        if ([[DataControl shareControl].nearMaleDic objectForKey:mail] == nil)
                        {
                            [[DataControl shareControl].nearMaleDic
                             setObject:[NSNumber numberWithInt:length ]
                             forKey:mail];
                        }
                        
                        [[DataControl shareControl].nearMaleShowArr addObject:mail];
                    }
                }
                
            }
            
            [DataControl shareControl].nearPeopleCurShowArr = [DataControl shareControl].nearMaleShowArr;
            [DataControl shareControl].nearPeopleCurDic = [DataControl shareControl].nearMaleDic;
        }
            break;
        default:
            break;
    }
    
    [[DataControl shareControl].UICommendDS addUICommand:UC_REFRESHCURVIEW];
    
    [self ShowLog];
}

@end
